<!--
 * @Descripttion: 
 * @Author: zhanyi
 * @Date: 2021-10-27 14:50:12
 * @FilePath: \wczd-mobile\src\pages\archives\archives-edit.vue
-->
<template>
  <div class="archives-edit">
    <secondTopPanel>
      <div slot='title'>作业许可管理详情</div>
    </secondTopPanel>
    <evanForm class="evan-form" :label-style="{width:'200upx',paddingRight:'20upx'}" :model='formData'>
      <evanFormItem label='作业名称' prop="jobType">
        {{formData.jobType}}
      </evanFormItem>
      <evanFormItem label='作业单位' prop="jobCompany">
        {{formData.jobCompany}}
      </evanFormItem>
      <evanFormItem label='作业区域' prop="jobAddress">
        {{formData.jobAddress}}
      </evanFormItem>
      <evanFormItem label='作业申请人' prop='jobApplyMan'>
        {{formData.jobApplyMan}}
      </evanFormItem>
      <evanFormItem label='作业审批人' prop="jobVerifyMan">
        {{formData.jobVerifyMan}}
      </evanFormItem>
      <evanFormItem label='作业内容' prop="jobContent">
        {{formData.jobContent}}
      </evanFormItem>
      <evanFormItem label='开始作业时间' prop="startTm">
        {{formData.startTm}}
      </evanFormItem>
      <evanFormItem label='结束作业时间' prop="endTm">
        {{formData.endTm}}
      </evanFormItem>
      <evanFormItem label='作业文件' label-position='top' prop='fileUrl'>
        <!-- <ImageUpload mediaType='all' :remove="false" :_max="formData.fileUrl.length" :imgUrlData='formData.fileUrl'></ImageUpload> -->
        <div class="file-item" v-for="(item,index) in formData.fileUrl" :key="index">
          {{item.name}}<span class="fileBtn" @click="download(item)">下载</span>
        </div>
      </evanFormItem>
    </evanForm>
  </div>
</template>

<script>
import secondTopPanel from '@/pages/component/top-panel/secondTopPanel.vue'
import evanForm from '@/components/evan-form/evan-form.vue'
import evanFormItem from '@/components/evan-form-item/evan-form-item.vue'
import ImageUpload from "@/pages/component/imageUpload/imageUpload.vue";
import { jobManagerInfoOne } from "@/api/jobManager";
import { getToken } from '@/utils/auth'//获取token

export default {
  name: 'archives-edit',
  components: { secondTopPanel, evanForm, evanFormItem, ImageUpload },
  data () {
    return {
      formData: {},
      token: (getToken() ? 'Bearer ' + getToken() : '')
    }
  },
  onLoad: function (option) {
    this._jobManagerInfoOne(option.id)
  },
  methods: {
    _jobManagerInfoOne (id) {
      jobManagerInfoOne({ id: id }).then(res => {
        res.data.fileUrl = []
        res.data.fileUrl = JSON.parse(res.data.fileId)
        res.data.fileUrl?.forEach(element => {
          element.url = process.uniEnv.baseUrl + '/profile' + element.url
        });
        this.formData = res.data
      })
    },
    download (item) {
      var _this = this
      // h5
      if (process.uniEnv.release === 'h5') {
        window.location.href = item.url + '?token=' + this.token
      } else {
        uni.downloadFile({
          url: item.url,
          success: function (res) {
            var path = res.tempFilePath
            if (res.statusCode === 200) {
              // preview
              uni.openDocument({
                filePath: path,
                success: function (res) {
                  console.log('打开文档成功');
                  console.log(res);
                }
              });
              //文件保存
              uni.saveFile({
                tempFilePath: path,
                success: function (res) {
                  _this.localPath = res.savedFilePath;
                  console.log(savedFilePath)
                  uni.showToast({
                    title: '下载成功',
                    content: savedFilePath,
                    duration: 500
                  });
                  uni.getSavedFileList({
                    success: function (res) {
                      console.log(res.fileList);
                    }
                  });
                }
              });
            }
          },
          fail (err) {
            console.log('下载失败', err)
          }
        });
      }
    }
  },
}
</script>

<style scoped lang="scss">
.archives-edit {
  height: 100%;
  .evan-form {
    height: 100%;
    overflow: auto;
    padding: 0 40upx;
    padding-top: 150upx;
    margin-top: 0;
    background-color: #fff;
  }
  .btn {
    margin-top: 40upx;
    display: flex;
    .submit {
      width: 90%;
      line-height: 80upx;
    }
    .temp-save {
      width: 40%;
      line-height: 80upx;
    }
  }
}
.fileBtn {
  color: #009fdf;
  padding-left: 10upx;
}
</style>
